package server

import (
	"github.com/gin-gonic/gin"
	"go.mongodb.org/mongo-driver/bson"
	"higame/config"
	"higame/modules/utils"
	"net/http"
)

func info(ctx *gin.Context) {
	totalMemory := int64(utils.TotalMemory() / 1024 / 1024)
	freeMemory := int64(utils.FreeMemory() / 1024 / 1024)
	osinfo := bson.A{
		bson.M{
			"key":   "操作系统",
			"value": utils.GetOSInfo(),
		},
		bson.M{
			"key":   "CPU架构",
			"value": utils.GetCpuInfo(),
		},
		bson.M{
			"key":   "内存总量",
			"value": utils.JoinString("%v MB", totalMemory),
		},
		bson.M{
			"key":   "空闲内存",
			"value": utils.JoinString("%v MB", freeMemory),
		},
		bson.M{
			"key":   "服务器时间",
			"value": utils.FormatTime(utils.Timestamp()),
		},
		bson.M{
			"key":   "运行时长",
			"value": utils.GetUpTime(),
		},
		bson.M{
			"key":   "后台版本",
			"value": config.Version,
		},
	}

	ctx.JSON(http.StatusOK, gin.H{
		"status": true,
		"text":   "",
		"data":   osinfo,
	})
}
